import request from './request'

// API 前缀
const API_PREFIX = '/api/v1'

// 分类接口
export const categoryApi = {
  // 获取分类列表
  getList(params) {
    return request({
      url: `${API_PREFIX}/categories/`,
      method: 'get',
      params
    })
  },

  // 获取分类详情
  getDetail(slug) {
    return request({
      url: `${API_PREFIX}/categories/${slug}/`,
      method: 'get'
    })
  },

  // 获取分类树
  getTree() {
    return request({
      url: `${API_PREFIX}/categories/tree/`,
      method: 'get'
    })
  },

  // 获取导航分类
  getNav() {
    return request({
      url: `${API_PREFIX}/categories/nav/`,
      method: 'get'
    })
  },

  // 获取子分类
  getChildren(slug) {
    return request({
      url: `${API_PREFIX}/categories/${slug}/children/`,
      method: 'get'
    })
  },

  // 获取祖先分类
  getAncestors(slug) {
    return request({
      url: `${API_PREFIX}/categories/${slug}/ancestors/`,
      method: 'get'
    })
  }
}

// 文档接口
export const documentApi = {
  // 获取文档列表
  getList(params) {
    return request({
      url: `${API_PREFIX}/documents/`,
      method: 'get',
      params
    })
  },

  // 获取文档详情
  getDetail(slug) {
    return request({
      url: `${API_PREFIX}/documents/${slug}/`,
      method: 'get'
    })
  },

  // 增加浏览量
  addView(slug) {
    return request({
      url: `${API_PREFIX}/documents/${slug}/views/`,
      method: 'post'
    })
  },

  // 获取最新文档
  getLatest(limit = 10) {
    return request({
      url: `${API_PREFIX}/documents/latest/`,
      method: 'get',
      params: { limit }
    })
  },

  // 获取推荐文档
  getRecommended(limit = 10) {
    return request({
      url: `${API_PREFIX}/documents/recommended/`,
      method: 'get',
      params: { limit }
    })
  },

  // 获取热门文档
  getPopular(limit = 10) {
    return request({
      url: `${API_PREFIX}/documents/popular/`,
      method: 'get',
      params: { limit }
    })
  },

  // 搜索文档
  search(params) {
    return request({
      url: `${API_PREFIX}/documents/search/`,
      method: 'get',
      params
    })
  }
}

// 标签接口
export const tagApi = {
  // 获取标签列表
  getList(params) {
    return request({
      url: `${API_PREFIX}/tags/`,
      method: 'get',
      params
    })
  },

  // 获取标签详情
  getDetail(slug) {
    return request({
      url: `${API_PREFIX}/tags/${slug}/`,
      method: 'get'
    })
  }
} 